const createDom = (type = 'div') => {
    return document.createElement(type)
}

const setAttribute = (dom, attribute) => {
    for (let i in attribute) {
        dom[i] = attribute[i]
    }
}

const setStyle = (dom, style) => {
    for (let i in style) {
        dom.style[i] = style[i]
    }
}

const insertDom = (container, attribute, style, type) => {
    const div = createDom(type)
    setAttribute(div, attribute)
    setStyle(div, style)
    container.appendChild(div)
    return div
}


const getStyle = (dom, cssName) => {
    return window.getComputedStyle(dom)[cssName]
}


const pxToNumber = (pxString) => {
    return Number(pxString.split('px')[0])
}

const imageLoad = (imageList, callback) => {
    let loadNum = 0
    const loadEvent = () => {
        loadNum++
        if (loadNum === Object.keys(imageList).length) {
            callback()
        }
    }
    for (let image in imageList) {
        imageList[image].addEventListener('load', loadEvent)
    }
}

export { createDom, setAttribute, setStyle, insertDom, getStyle, pxToNumber, imageLoad }